package com.prp.gwt.client.widgets.entry;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.prp.gwt.client.entry.EntryClientListener;

public class ForgetPasswordPanel extends VerticalPanel{

	private static ForgetPasswordPanel instance;
	private HTML message = new HTML("");
	private TextBox email = new TextBox();
	
	public static ForgetPasswordPanel getInstance(){
		if(instance == null)
			instance = new ForgetPasswordPanel();
		return instance;
	}
	
	private ForgetPasswordPanel(){
		Hyperlink back  = new Hyperlink("<<返回登录页面", "");
		add(back);
		back.addClickHandler(new ClickHandler(){
			@Override
			public void onClick(ClickEvent event) {
				WelcomeView.getInstance().showWidget(0);
			}
		});
		add(new HTML("请输入您的注册邮箱，以便我们帮您找回密码。"));
		
		HorizontalPanel panel = new HorizontalPanel();
		panel.setSpacing(20);
		Button button = new Button("提交");
		panel.add(email);
		panel.add(button);
		add(panel);
		add(message);
		
		button.addClickHandler(new ClickHandler(){
			@Override
			public void onClick(ClickEvent event) {
				if(null == email.getText() || email.getText().equals("")){
					message.setText("请输入邮箱地址");
					return;
				}
				EntryClientListener.getInstance().retrievePassword(email.getText());
				message.setText("");
			}
		});
	}
	
	public void showMessage(String text){
		message.setText(text);
	}
	
}
